package huoye.shops.huoye.operation.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.codeideology.android.widget.recycler.RecyclerViewAdapter;

import java.math.BigDecimal;

import butterknife.BindView;
import huoye.shops.R;
import huoye.shops.base.APIUrls;
import huoye.shops.huoye.operation.model.DiscountCancelData;
import huoye.shops.huoye.operation.model.GoodInfo;
import huoye.shops.huoye.operation.model.ManageEventData;
import huoye.shops.utils.StockUtils;
import huoye.shops.widget.RoundImageView;


/**
 * Created by uesr on 2018/8/10.
 */

public class DiscountCancelAdapter extends RecyclerViewAdapter<DiscountCancelAdapter.ViewHolder,DiscountCancelData> {




    public DiscountCancelAdapter(Context context) {
        super(context, R.layout.item_discount_cancel);
    }

    @Override
    protected ViewHolder initViewHolder(View view, int i) {

        return new ViewHolder(view);
    }

    @Override
    protected void bindView(ViewHolder holder, final DiscountCancelData data, int i) {

        if(getContext() != null){
            Glide.with(getContext())
                    .load(data.getHeadImg())
                    .dontAnimate()
                    .placeholder(R.mipmap.ic_wait_logo)
                    .error(R.mipmap.ic_error)
                    .into(holder.rvHead);
        }

        holder.tvName.setText(data.getNickName());
        if(data.getiState() == 0){
            holder.tvStare.setText("未核销");
        }else {
            holder.tvStare.setText("已核销");
        }

        GoodInfo goodInfo =  data.getGoodInfo();
        if(getContext() != null){
            Glide.with(getContext())
                    .load(APIUrls.COMMON_CONFIG.TYPE_COMMON_ALIYUN+goodInfo.getShowImg())
                    .dontAnimate()
                    .placeholder(R.mipmap.ic_wait_logo)
                    .error(R.mipmap.ic_error)
                    .into(holder.rvShop);
        }

        holder.tvShop.setText(goodInfo.getTitle());



        String moenyNum = StockUtils.moenyStyle(goodInfo.getSaleMoney());
        holder.tvMoneyOriginal.setVisibility(View.VISIBLE);
        holder.tvMoneyOriginal.setText(moenyNum + "");
        String s = String.valueOf(moenyNum);
        Float valueOf = Float.valueOf(s);
        float a = goodInfo.getDiscount();
        float v = a * valueOf / 100;
        String s1 = String.valueOf(v);
        holder.tvMoneyDiscount.setText("￥"+ StockUtils.moenyStyle(s1));
        ////中间横线
        holder.tvMoneyOriginal.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        // 抗锯齿
        holder.tvMoneyOriginal.getPaint().setAntiAlias(true);



        holder.tvDiscountType.setText(goodInfo.getDisTypeName());



    }


    public class ViewHolder extends RecyclerViewAdapter.ViewHolder {

        @BindView(R.id.item_discount_cancel_tv_name)
        TextView tvName;
        @BindView(R.id.item_discount_cancel_tv_state)
        TextView tvStare;
        @BindView(R.id.item_discount_cancel_tv_shop)
        TextView tvShop;
        @BindView(R.id.item_discount_cancel_tv_discount_type)
        TextView tvDiscountType;
        @BindView(R.id.item_discount_cancel_tv_money_discount)
        TextView tvMoneyDiscount;
        @BindView(R.id.item_discount_cancel_tv_money_original)
        TextView tvMoneyOriginal;


        @BindView(R.id.item_discount_cancel_rv_head)
        RoundImageView rvHead ;
        @BindView(R.id.item_discount_cancel_rv_shop)
        RoundImageView rvShop ;



        public ViewHolder(View itemView) {
            super(itemView);
        }
    }



    public void setOnManageEventDataListener(OnManageEventDataListener onManageEventDataListener) {
        this.listener = onManageEventDataListener;
    }

    private OnManageEventDataListener listener;

    public interface OnManageEventDataListener {

        void onJoinClick(ManageEventData ManageEventData);


    }

}
